package top.shiyiri.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Aunean
 * @date 2022/2/10 16:05
 */
public class LoginServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        if ("qaz".equals(username) && "123".equals(password)) {
            req.getSession().setAttribute("user", username);
            resp.getWriter().write("登录成功");
        } else {
            req.getRequestDispatcher("/login.jsp").forward(req, resp);
        }
    }

}
